package com.example.demo.candycrush.strategy;

import com.example.demo.candycrush.model.ProcessResult;

/**
 * Stage 1
 */
public class RemoveStrategy implements CrushStrategy {
    @Override
    public ProcessResult process(String input) {
        if (input == null || input.length() < 3) return null;
        
        for (int i = 0; i < input.length(); ) {
            int j = i + 1;
            while (j < input.length() && input.charAt(j) == input.charAt(i)) j++;
            
            if (j - i >= 3) {
                String newString = input.substring(0, i) + input.substring(j);
                return new ProcessResult(newString, null);
            } else {
                i = j;
            }
        }
        return null;
    }
}